<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>组织类型信息设置管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treeview.jsp" %>
	<script type="text/javascript">
			var zNodes=[];
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm") .validate({
				submitHandler: function(form){
					var ids = [], nodes = tree.getCheckedNodes(true);
					for(var i=0; i<nodes.length; i++) {
						ids.push(nodes[i].id);
					}
					if(ids.length==0){
						alert("请选择党组织信息");
						return false;
					}else{
						$("#orgIds").val(ids);
						loading('正在提交，请稍等...');
						form.submit();
					}
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$("#pzBtn").on('click', function() {
				var organizationId=$("#organizationId").val();
				window.location.href="${ctx}/partysinfo/partysInfo/peizhi?organizationId="+organizationId;
			});
			
			var setting = {
					check:{enable:true,nocheckInherit:true},
					view:{selectedMulti:false},
					data:{simpleData:{enable:true}},
					async: {
						enable: true,
						url:"gettreeData",
						autoParam:["id"],
						dataFilter: filter
					},
					callback:{
						beforeClick:function(id, node){
							tree.checkNode(node, !node.checked, true, true);
							return false;
						},
						beforeAsync: beforeAsync,
						onAsyncSuccess: onAsyncSuccess
					}};
			function beforeAsync(treeId, treeNode) {
				return true;
			}
			function onAsyncSuccess(event, treeId, treeNode, msg) {
			}
			function filter(treeId, parentNode, childNodes) {
				if (!childNodes) return null;
				for (var i=0, l=childNodes.length; i<l; i++) {
					childNodes[i].id = childNodes[i].id;
					childNodes[i].name = childNodes[i].name;
					childNodes[i].pId = childNodes[i].pId;
					 if(childNodes[i].hasChildren=="1"){
						childNodes[i].isParent=true;
					}
				}
				return childNodes;
			}
			
			// 用户-菜单
			//load();
			// 初始化树结构
			//var tree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
			var tree = $.fn.zTree.init($("#menuTree"), setting);
			// 不选择父节点
			tree.setting.check.chkboxType =  { "Y" : "s", "N" : "ps" };
			// 默认选择节点
			var ids = "${partysInfo.orgIds}".split(",");
			for(var i=0; i<ids.length; i++) {
				var node = tree.getNodeByParam("id", ids[i]);
				try{tree.checkNode(node, true, false);}catch(e){}
			}
			
		});
		function load(){
			zNodes = [];
			$.ajax({
				type : 'GET',
				url :"gettreeData",
				dataType : 'json',
				async:false,
				contentType : 'application/json',
				success : function(result) {
					$.each(result, function(k, map) {
						createNode(map);
					});
				}
			});
		}
		function createNode(map) {
			var node = new Object();
			node.id = map.id;
			node.name = map.name;
			node.pId = map.pId;
			//node.open = true;
			zNodes.push(node);
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/partysinfo/partysInfo/form?id=${partysInfo.id}">组织类型信息设置
		<shiro:hasPermission name="partysinfo:partysInfo:edit">${not empty partysInfo.id?'修改':'添加'}
		</shiro:hasPermission><shiro:lacksPermission name="partysinfo:partysInfo:edit">查看</shiro:lacksPermission>
		</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="partysInfo" action="${ctx}/partysinfo/partysInfo/save" 
	method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<!-- <div class="control-group">
			<label class="control-label">党组织信息：</label>
			<div class="controls">
			</div>
		</div> -->
		<div class="control-group">
			<label class="control-label">党组织信息名称：</label>
			<div class="controls">
			<div id="menuTree" class="ztree" style="margin-top:3px;float:left;"></div>
				<form:hidden path="orgIds"/>
				<%-- <sys:treeselect id="organization" name="organizationId" value="${partysInfo.organizationId}" 
				labelName="partysInfo.organizationName" labelValue="${partysInfo.organizationName}"
					title="部门" url="/partysinfo/partysInfo/treeData?organizationId=${organizationId}" 
					cssClass="required"/>
					<input id="pzBtn" class="btn btn-primary" type="button" value="配置"/> --%>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">党组织类型：</label>
			<div class="controls">
				<form:select path="typeId" class="input-medium required">
					<form:options items="${partyTypelist}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">状态：</label>
			<div class="controls">
				<form:select path="state" class="input-xlarge ">
					<form:options items="${fns:getDictList('Start_Stop')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="partysinfo:partysInfo:edit">
			<!-- <input id="baocun" class="btn btn-primary" type="button" value="保 存"/> -->
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>